The data used for this assignment details mass shootings for the past five years. Each entry includes the date, state, number of people who died, number of people that were injured and a small description describing what happened. The data is available on Kaggle at https://www.kaggle.com/datasets/hemil26/mass-shootings-in-united-states-20182022?select=shootings_2018.csv.
states <- map_data("state")
states = states %>%
mutate(State = str_to_title(region))
shootings2018 = read.csv("shootings_2018.csv")
shootings2018 = shootings2018 %>%
group_by(State) %>%
summarise(DeathTotal = sum(Dead))
stateShootings = states %>%
left_join(shootings2018, by = "State") %>%
select(-c(region, subregion))
head(stateShootings)
## long lat group order State DeathTotal
## 1 -87.46201 30.38968 1 1 Alabama 11
## 2 -87.48493 30.37249 1 2 Alabama 11
## 3 -87.52503 30.37249 1 3 Alabama 11
## 4 -87.53076 30.33239 1 4 Alabama 11
## 5 -87.57087 30.32665 1 5 Alabama 11
## 6 -87.58806 30.32665 1 6 Alabama 11
p_death2018 = ggplot(data = stateShootings,
mapping = aes(x = long, y = lat, group = group, fill = DeathTotal,
text = paste("Shooting Deaths in 2018: ", DeathTotal))) +
geom_polygon(color = "white") +
ggdendro::theme_dendro() +
scale_fill_viridis(option = "magma", direction = -1) +
coord_map() +
guides(fill = guide_legend(title = "Deaths")) +
ggtitle("Mass Shootings in 2018")
ggplotly(p_death2018, tooltip = "text")
t_states <- tigris::states(cb = TRUE, resolution = '20m')
## Retrieving data for the year 2020
##
|
| | 0%
|
|======= | 10%
|
|========= | 13%
|
|========== | 14%
|
|=========== | 16%
|
|============ | 17%
|
|============= | 19%
|
|============== | 20%
|
|=============== | 21%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 29%
|
|====================== | 31%
|
|======================= | 33%
|
|======================= | 34%
|
|========================= | 36%
|
|====================================== | 55%
|
|======================================== | 57%
|
|=========================================== | 61%
|
|============================================= | 64%
|
|=============================================== | 68%
|
|======================================================================| 100%